package com.meida.module.product.provider.controller;


import com.meida.common.mybatis.model.GetModel;
import com.meida.common.mybatis.model.ListModel;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.common.springmvc.base.BaseController;
import com.meida.module.product.client.entity.ProdShop;
import com.meida.module.product.provider.service.ProdShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 商家管理控制器
 *
 * @author flyme
 * @date 2019-06-17
 */
@RestController
@Api(tags = "商家管理")
@RequestMapping("/shop/")
public class ProdShopController extends BaseController<ProdShopService, ProdShop> {

    @ApiOperation(value = "商家分页列表", notes = "商家分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    /**
     * 更新企业店铺信息
     */
    @ApiOperation(value = "更新企业店铺信息", notes = "更新企业店铺信息")
    @PostMapping(value = "company/update")
    public ResultBody companyUpdate(@RequestParam(required = false) Map params) {
        CriteriaSave cs = new CriteriaSave(params, ProdShop.class);
        return bizService.setProdShop(cs);
    }

    @ApiOperation(value = "店铺-列表", notes = "店铺列表 ")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    /**
     * 更新店铺
     */
    @ApiOperation(value = "店铺-更新", notes = "只更新非空字段")
    @PostMapping(value = "edit")
    public ResultBody edit(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "企业店铺-列表", notes = "企业店铺列表 ")
    @GetMapping(value = "company/list")
    public ResultBody companyList(@ModelAttribute(value = "model") ListModel model) {
        return bizService.listByCompany(model);
    }

    @ApiOperation(value = "店铺-详情", notes = "商品详情")
    @GetMapping(value = "detail")
    public ResultBody get(@ModelAttribute(value = "model") GetModel model) {
        return bizService.get(model);
    }

    @ApiOperation(value = "企业店铺-详情", notes = "商品详情")
    @GetMapping(value = "company/detail")
    public ResultBody companyGet(@ModelAttribute(value = "model") GetModel model) {
        return bizService.getByCompany(model);
    }

    @ApiOperation(value = "删除店铺", notes = "删除店铺")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "店铺-详细信息", notes = "查询企业详细信息")
    @GetMapping(value = "details")
    public ResultBody details(@ModelAttribute(value = "model") GetModel model) {
        return bizService.get(model);
    }

    @ApiOperation(value = "更新电话查看量", notes = "更新电话查看量")
    @PostMapping(value = "updateLookCount")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", required = true, value = "主键", paramType = "form")
    })
    public ResultBody updateLookCount(@RequestParam(value = "shopId") Long shopId) {
        return bizService.updateLookCount(shopId, 1);
    }

}
